<?php

/**
 * @author [TinyBear]
 * @copyright 2011
 * @action  
 */


require_once('toauth/qq.oauth.php');

$oOAuth = new TOAuth($_SESSION["appk"], $_SESSION["appks"]);

$aParam = array(
	"oauth_token" => $_GET["oauth_token"],
	"oauth_verifier" => $_GET["oauth_verifier"],
);

$t_oauth_token_secret = $_SESSION["oauth_token_secret"];

$oOAuth->setToken($aParam["oauth_token"],$t_oauth_token_secret);
$sURL =  TOAuth::$oauth_access_token;
$sReturn = $oOAuth->send($aParam, $sURL);
parse_str($sReturn, $aReturn);

$_SESSION["oauth_token"] = $aReturn["oauth_token"];
$_SESSION["oauth_token_secret"] =  $aReturn["oauth_token_secret"];

$ot = $_SESSION["oauth_token"];
$ots = $_SESSION["oauth_token_secret"];
$otime = time();

$oOAuth->setToken($ot,$ots);
$aParam = array(
	"format" => "json",
);
$sURL = "http://open.t.qq.com/api/user/info";
$sReturn = $oOAuth->send($aParam, $sURL, "GET");
$aReturn = json_decode($sReturn, TRUE);

if(isset($aReturn['ret'])&&$aReturn['ret']==0) {
    $name = $aReturn['data']['name'];
    $nick = $aReturn['data']['nick'];
    //echo '��Ȩ�ɹ�';
	/*$db = new DB();
	$db->connect(UC_DBHOST, UC_DBUSER, UC_DBPW, UC_DBNAME, UC_DBCHARSET, UC_DBCONNECT, UC_DBTABLEPRE);
    $db->query("DELETE FROM ".UC_DBTABLEPRE."qq_oauth WHERE uname = '".$name."'");
	$db->query("INSERT INTO ".UC_DBTABLEPRE."qq_oauth VALUES (null,'".$ot."','".$ots."','".$name."','".$nick."','".$otime."')");
	if($db->affected_rows()) {
		//echo '������ݿ�ɹ�';
		header("Location:"."index.php"); 
	}*/

    print_r($aReturn);
} else {
    //echo '��Ȩʧ��';
    header("Location:"."error.php"); 
}



?>